package me.yricky.alia.utils

/**
 * @author Yricky
 * @date 2022/1/29
 */
fun safe(l:()->Unit){
    try {
        l()
    }catch (e:Throwable){
        println("Exception from safe block!")
        e.printStackTrace()
    }
}

typealias ProgressHandler = (Float)->Unit

inline fun <T> Iterable<T>.filterAnd(filter:(T)->Boolean):Pair<List<T>,List<T>>{
    val arr1 = ArrayList<T>()
    val arr2 = ArrayList<T>()
    iterator().forEach {
        if (filter(it)){
            arr1.add(it)
        }else {
            arr2.add(it)
        }
    }
    return Pair(arr1,arr2)
}

inline fun <T, reified R> Iterable<T>.filterInstanceAnd():Pair<List<T>,List<R>>{
    val arr1 = ArrayList<T>()
    val arr2 = ArrayList<R>()
    iterator().forEach {
        if (it is R){
            arr2.add(it)
        }else {
            arr1.add(it)
        }
    }
    return Pair(arr1,arr2)
}